<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
include "secure/sub_account_permission.php";

class Employers extends Sub_account_permission {
	
	public function __construct(){
		parent::__construct();
		if ($this -> session -> userdata('employer_active_access')) {
			
		}
		$this->output->nocache();
		$this -> form_validation -> set_error_delimiters('<p class="help-block danger">', '</p>');
	}
	public function index() {
		if ($this -> session -> userdata('employer_active_access')) {
			redirect("employers/welcome");
		}
		
		$data['title'] = "Employers";
		$data['locations'] = $this -> model_globals -> select_all('job_locations');
		$categories = $this -> model_globals -> select_all('job_categories') -> result();
		$option = $this->get_job_category_options($categories);
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function welcome() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['username'] = $this -> get_name_employer();
		$data['title'] = "Employer Account";
		$this->load->model('F-MODEL/model_employers');
		$data['current_jobs']=$this->model_employers->get_current_job_apply($this -> session -> userdata('employer_active_access'));
		//$data['sub_accounts'] = $this -> model_globals -> select_where('employers', array('using_sub_account_of_employer' => $this -> session -> userdata('employer_active_access'))) -> result();
		
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['username'] = $this -> get_name_employer();
		$data['title'] = "Employers";

		$data['locations'] = $this -> model_globals -> select_all('job_locations');
		$categories = $this -> model_globals -> select_all('job_categories') -> result();
		$option = $this->get_job_category_options($categories);
		$data['categories'] = $option;
		$data['job_types'] = $this -> model_globals -> select_all('job_types');
		$data['job_terms'] = $this -> model_globals -> select_all('job_term');
		$data['edu_levels'] = $this -> model_globals -> select_all('education_levels');
		$data['contact_persons'] = $this -> model_globals -> select_where('contact_persons', array('using_employer_id' => $this -> session -> userdata('employer_active_access')));

		$this -> load -> model('F-MODEL/model_employers');
		$data['current_job_ads'] = $this -> model_employers -> get_manage_current_job();
		//$data['current_job_ads']=$this->model_globals->select_where('job_ads',array('using_employer_id'=>$this->session->userdata('employer_active_access'),'date_availables>=DAYNAME(CURDATE()'));
		$data['expired_job_ads'] = $this -> model_employers -> get_manage_expired_job();
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function jobseekers_registration() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['username'] = $this -> get_name_employer();
		$data['title'] = "Employers";
		
		if(!$this->input->get('search')){
			$data['laguags'] = $this->model_globals->select_all('languages',150);    
	        $data['education_level']= $this->model_globals->select_all('education_levels',30);
			$data['locations'] = $this -> model_globals -> select_all('job_locations');
			$categories = $this -> model_globals -> select_all('job_categories') -> result();
			$option = $this->get_job_category_options($categories);
			$data['categories'] = $option;
			$this -> load -> view(F_MASTER . "index", $data);
		}else{
			$education=$this->input->get('education');
			$native=$this->input->get('native-language');
			$foreign=$this->input->get('foreign-language');
			$previos_employer=$this->input->get('previous-employer');
			$job_title=$this->input->get('job-title');
			$keyword=$this->input->get('key-word');
			$category=$this->input->get('category');
			$location=$this->input->get('location');
			
			$data['jobseekers']=$this->model_employers->search_jobseeker_registration($education,$native,$foreign,$previos_employer,$job_title,$category,$location,$keyword);
			$data['search']=TRUE;
			$this -> load -> view(F_MASTER . "index", $data);
		}
		 
	}

	public function feature() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Feature employers";
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function login() {
		$data['title'] = "Employers login";
		if ($this -> session -> userdata('employer_active_access')) {
			redirect("employers/welcome");
		} else {
			$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
			$this -> form_validation -> set_rules('password', 'Password', 'required');
			//$this -> form_validation -> set_error_delimiters('<div class="alert alert-danger" style="position:absolute;top:20px;text-align:center; width:92%;">', '</div>');

			if ($this -> form_validation -> run() == FALSE) {
				$data['locations'] = $this -> model_globals -> select_all('job_locations');
				$categories = $this -> model_globals -> select_all('job_categories') -> result();
				$option = $this->get_job_category_options($categories);
				$data['categories'] = $option;
				$data['feature_jobs']=$this->model_jobs->fearture_job();
				$this -> load -> view(F_MASTER . "index", $data);
			} else {
				$data_logged = array('email' => $this -> input -> post('email'), 'password' => sha1($this -> input -> post('password')));

				$login_check = $this -> model_globals -> select_where('employers', $data_logged);
				if ($login_check -> num_rows == 1) {
					$status=$login_check->row()->status;
					if($status!=1){
						$this->session->set_flashdata('warning',"Your account was not activated yet.Please check you email to activation account or click link below to resend your activation account.<br /><a href='".base_url()."employers/resent-activation-account'>Resent your activation account</a>");
						redirect('employers/login');
					}else{
						//$this -> session -> sess_destroy();
						if ($this -> session -> userdata('jobseeker_active_access')) {
							$this -> session -> unset_userdata('jobseeker_active_access');
						}
						$check_sub_account_info=$this->model_globals->select_where('employers',array('employer_id'=>$login_check -> row() -> employer_id));
						$is_sub_account=$check_sub_account_info->row()->is_sub_account;
						$employer_account_id=$check_sub_account_info->row()->using_sub_account_of_employer;
						if($is_sub_account=='YES'){
						
							$this -> session -> set_userdata('is_employer_owner', $employer_account_id);
						}
						$this -> session -> set_userdata('employer_active_access', $login_check -> row() -> employer_id);
						redirect('employers/welcome');	
					}
					
					
				} else {
					$this -> session -> set_flashdata('error_login', TRUE);
					redirect('employers/login');
				}
			}
		}

	}

	public function register() {
		if ($this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Employers registration";

		$this -> form_validation -> set_rules('username', 'Username', 'required');
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email|is_unique[employers.email]');
		$this -> form_validation -> set_rules('company', 'company', 'required|min_length[2]|max_length[50]');
		$this -> form_validation -> set_rules('password', 'Password', 'required|matches[conf_password]|min_length[6]|max_length[50]');
		$this -> form_validation -> set_rules('conf_password', 'Password Confirmation', 'required|min_length[6]|max_length[50]');

		if ($this -> form_validation -> run() === FALSE) {
			$data['locations'] = $this -> model_globals -> select_all('job_locations');
			$categories = $this -> model_globals -> select_all('job_categories') -> result();
			$option = $this->get_job_category_options($categories);
			$data['feature_jobs']=$this->model_jobs->fearture_job();
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$token_key = random_string('alnum', 25);
			if ($this -> input -> post('subscribe', TRUE) == 1) {
				$subscribe = "YES";
			} else {
				$subscribe = "NO";
			}
			$data_employer = array('username' => $this -> input -> post('username', TRUE), 'email' => $this -> input -> post('email', TRUE), 'password' => sha1($this -> input -> post('password', TRUE)), 'subscribe' => $subscribe, 'is_sub_account' => 'NO', 'using_sub_account_of_employer' => 0, 'status' => 0, 'token_key' => $token_key, 'created_date' => null);

			$is_inserted_employer_with_return_id = $this -> model_globals -> insert_get_last_id('employers', $data_employer);

			if ($is_inserted_employer_with_return_id) {
				$company_key = random_string('alnum', 25);
				$data_company = array('using_employer_id' => $is_inserted_employer_with_return_id, 'name' => $this -> input -> post('company', TRUE), 'description' => $this -> input -> post('company_desc', TRUE), 'address' => $this -> input -> post('address', TRUE), 'phone' => $this -> input -> post('phone', TRUE), 'fax' => $this -> input -> post('fax', TRUE), 'website' => $this -> input -> post('website', TRUE), 'logo' =>NULL, 'company_keys'=>$company_key,'status' => 1, 'created_date' => null);
				$is_inserted_employer_contact_company = $this -> model_globals -> insert('companies', $data_company);
				if ($is_inserted_employer_contact_company) {

					$modules = $this -> model_globals -> select_all('employer_modules');
					foreach ($modules->result() as $module) {
						$module_id = $module -> employer_module_id;
						$this -> model_globals -> insert('employer_module_permissions', array('using_employer_id' => $is_inserted_employer_with_return_id, 'using_employer_module_id' => $module_id, 'is_access' => 'YES', 'status' => 1, 'created_date' => null));
					}
					//sent activation link
					//http:www.jobpending.com/employers/activation-account/ICiiwwpeurnfdksivnEjueT
					//$activation_key=random_string('alnum', 25);
					$email=$this->input->post('email');
					
					$is_send_activate_account=$this->send_mail_to_employer_activation_account($token_key,$email);
					if($is_send_activate_account){
						$this -> session -> set_flashdata('success', 'Your account  was created success !.Please check your email account that you have registed to active your account.');
						redirect('employers/login');
					}else{
						$this -> session -> set_flashdata('warning', 'Your account  was created success !,but we feel sorry with send mail to activation account.Please help to provide your email registration again to resent your activation account.Thank you !');
						redirect('employers/resent-activation-account');
					}
									
				}

				$this -> session -> set_flashdata('error', 'Your account contact info  was created fail !.');
				redirect('employers/register');
			} else {
				$this -> session -> set_flashdata('error', 'Your account  was created fail !.');
				redirect('employers/register');
			}
		}

	}
	
	public function resent_activation_account(){
		$data['title'] = "Resent activation account";
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		if ($this -> form_validation -> run() === FALSE) {
			$data['feature_jobs']=$this->model_jobs->fearture_job();
			$data['locations'] = $this -> model_globals -> select_all('job_locations');
			$categories = $this -> model_globals -> select_all('job_categories') -> result();
			$option = $this->get_job_category_options($categories);
			$data['categories'] = $option;
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$email = $this -> input -> post('email');
			$checking_email = $this -> model_globals -> select_where('employers', array('email' => $email));
			if ($checking_email -> num_rows() == 1) {
				//$first_name=$checking_email->row()->first_name;
				//$last_name=$checking_email->row()->last_name;
				$username = $checking_email -> row() -> username;
				$token_key = random_string('alnum', 25);
				$update_token_key = $this -> model_globals -> update('employers', array('token_key' => $token_key), array('email' => $email));
				if ($update_token_key) {
					//send mail to user with activation link
					//http:www.jobpending.com/employers/activation_forgotten_password/ekeii#EwiTjjwjwwk
					//$activation_key=$token_key=random_string('alnum', 25);
					$is_sent_resent_activate=$this->send_mail_to_employer_resend_activate_account($token_key,$email);
					if($is_sent_resent_activate){
						$this -> session -> set_flashdata('success', 'Your request to resent activation account success!.Please checking your email to reset new password.');
						redirect('employers/resent-activation-account');
					}else{
						$this->session->set_flashdata('error','Your request to resent activation account fail!.Please try again.');
						redirect('employers/resent-activation-account');
					}
					
				} else {
					$this -> session -> set_flashdata('error', 'There is has error occured. Please try again !');
					redirect('employers/resent-activation-account');
				}
			} else {
				$this -> session -> set_flashdata('error', 'Your email that you have provided is wrong !');
				redirect('employers/resent-activation-account');
			}
		}
	}
	public function forgotten() {
		$data['title'] = "Employer forgotten password";
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		if ($this -> form_validation -> run() === FALSE) {
			$data['feature_jobs']=$this->model_jobs->fearture_job();
			$data['locations'] = $this -> model_globals -> select_all('job_locations');
			$categories = $this -> model_globals -> select_all('job_categories') -> result();
			$option = $this->get_job_category_options($categories);
			$data['categories'] = $option;
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$email = $this -> input -> post('email');
			$checking_email = $this -> model_globals -> select_where('employers', array('email' => $email));
			if ($checking_email -> num_rows() == 1) {
				//$first_name=$checking_email->row()->first_name;
				//$last_name=$checking_email->row()->last_name;
				$username = $checking_email -> row() -> username;
				$token_key = random_string('alnum', 25);
				$update_token_key = $this -> model_globals -> update('employers', array('token_key' => $token_key), array('email' => $email));
				if ($update_token_key) {
					//send mail to user with activation link
					//http:www.jobpending.com/employers/activation_forgotten_password/ekeii#EwiTjjwjwwk
					//$key_active_password=random_string('alnum', 25);
					$is_sent_reset_password=$this->send_mail_to_employer_reset_password($token_key,$email);
					if($is_sent_reset_password){
						$this -> session -> set_flashdata('success', 'Your request to reset new password was confirmed.Please checking your email to reset new password.');
						redirect('employers/forgotten');
					}else{
						$this->session->set_flashdata('error','Your request to reset new password was confirmed please.Please try again.');
						redirect('employers/forgotten');
					}
					
				} else {
					$this -> session -> set_flashdata('error', 'There is has error occured. Please try again !');
					redirect('employers/forgotten');
				}
			} else {
				$this -> session -> set_flashdata('error', 'Your email that you have provided is wrong !');
				redirect('employers/forgotten');
			}
		}

	}

	public function activation_account() {
		$data['title'] = "Employer Activation an Account";
		$token_key = $this -> uri -> segment(3);
		$checking_actavate_key = $this -> model_globals -> select_where("employers", array('token_key' => $token_key));
		if ($checking_actavate_key->num_rows()>0) {
			$set_active_account = $this -> model_globals -> update('employers', array('status' => 1), array('token_key' => $token_key));
			if ($set_active_account) {
				$this -> session -> set_flashdata('success', 'Your account was actived success.Please login to your account !');
				redirect("employers/login");
			} else {
				$data['feature_jobs']=$this->model_jobs->fearture_job();
				$data['wrong_activation']='There is an error occured.Please try again !';
				$this -> load -> view(F_MASTER . "index", $data);
			}
		} else {
			$data['feature_jobs']=$this->model_jobs->fearture_job();
			$data['wrong_activation'] = "Your activation link is wrong. Please try again !";
			$this -> load -> view(F_MASTER . "index", $data);

		}
	}

	public function activation_forgotten_password() {
		$data['title'] = "Employer Activation Forgotten Password";
		$token_key = $this -> uri -> segment(3);
		$checking_activate_key = $this -> model_globals -> select_where("employers", array('token_key' => $token_key));
		if ($checking_activate_key->num_rows()>0) {
			$this -> session -> set_userdata('activation_password_employer', $checking_activate_key -> row() -> employer_id);
			redirect('employers/reset-password');
		} else {
			$data['feature_jobs']=$this->model_jobs->fearture_job();	
			$data['wrong_activation'] = "Your activation link is wrong. Please try again !";
			$this -> load -> view(F_MASTER . "index", $data);

		}
	}

	public function reset_password() {
		$data['title'] = "Employer Reset Password";
		if ($this -> session -> userdata('activation_password_employer')) {
			$this -> form_validation -> set_rules('password', 'Password', 'required|matches[conf_password]|min_length[6]|max_length[50]');
			$this -> form_validation -> set_rules('conf_password', 'Password Confirmation', 'required|min_length[6]|max_length[50]');

			if ($this -> form_validation -> run() === FALSE) {
				$data['feature_jobs']=$this->model_jobs->fearture_job();	
				$this -> load -> view(F_MASTER . "index", $data);
			} else {
				$data = array('password' => sha1($this -> input -> post('password', TRUE)));
				$is_updated = $this -> model_globals -> update("employers", $data, array("employer_Id" => $this -> session -> userdata('activation_password_employer')));
				if ($is_updated) {
					$this->session->unset_userdata('activation_password_employer');
					$this -> session -> set_flashdata('success', "You have reseted your password success !");
					redirect('employers/login');
				} else {
					$this -> session -> set_flashdata('error', "You have reseted your password fail !");
					redirect('employers/login');
				}
			}
		} else {
			redirect("employers/login");
		}
	}

	public function new_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}

		$data['title'] = "Create Job ads";
		$data['username'] = $this -> get_name_employer();

		$this -> form_validation -> set_rules('category', 'Job Category', 'required');
		$this -> form_validation -> set_rules('location', 'Location', 'required');
		$this -> form_validation -> set_rules('job_terms', 'Job Terms', 'required');
		$this -> form_validation -> set_rules('title', 'Job Title', 'required');
		$this -> form_validation -> set_rules('date_available', 'Date Available', 'callback_available_check');
		$this -> form_validation -> set_rules('contact_person', 'Contact Person', 'required');
		
		//Prepping Data
		$this -> form_validation -> set_rules('job_type', '', '');
		$this -> form_validation -> set_rules('edu_level', '', '');
		$this -> form_validation -> set_rules('gender', '', '');
		$this -> form_validation -> set_rules('active', '', '');
		$this -> form_validation -> set_rules('notification', '', '');

		if ($this -> form_validation -> run() === FALSE) {
			$data['locations'] = $this -> model_globals -> select_all('job_locations');
			$categories = $this -> model_globals -> select_all('job_categories') -> result();
			$option = $this->get_job_category_options($categories);
			$data['categories'] = $option;
			$data['job_types'] = $this -> model_globals -> select_all('job_types');
			$data['job_terms'] = $this -> model_globals -> select_all('job_term');
			$data['edu_levels'] = $this -> model_globals -> select_all('education_levels');
			$data['contact_persons'] = $this -> model_globals -> select_where('contact_persons', array('using_employer_id' => $this -> session -> userdata('employer_active_access')));

			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$date_available_input = explode("/", $this -> input -> post('date_available'));
			$date_available_db = $date_available_input[2] . "-" . $date_available_input[1] . "-" . $date_available_input[0];
			$token_key = "";
			$job_key = random_string('alnum', 12);
			while ($this -> isExist($job_key)) {
				$job_key = random_string('alnum', 12);
			}
			$splite_category = explode("-", $this -> input -> post('category'));
			$company_id=$this->model_globals->select_string('companies','company_id',array('using_employer_id' => $this -> session -> userdata('employer_active_access')));
			$data = array('using_company_id'=>$company_id,'posted_by' => 'employer', 'using_employer_id' => $this -> session -> userdata('employer_active_access'), 'job_keys' => $job_key, 'using_job_category_id' => $splite_category[0], 'using_job_sub_category_id' => $splite_category[1], 'using_job_location_id' => $this -> input -> post('location'), 'using_job_type_id' => $this -> input -> post('job_type'), 'using_contact_person_id' => $this -> input -> post('contact_person'), 'using_job_term_id' => $this -> input -> post('job_terms'), 'using_education_level_id' => $this -> input -> post('edu_level'), 'title' => $this -> input -> post('title'), 'salary' => $this -> input -> post('salary'), 'age' => $this -> input -> post('age'), 'hiring' => $this -> input -> post('num_hiring'), 'date_available' => $date_available_db, 'text_description' => $this -> input -> post('description'), 'text_requirements' => $this -> input -> post('requirement'), 'notification' => $this -> input -> post('notification'), 'gender' => $this -> input -> post('gender'), 'status' => $this -> input -> post('active'), 'created_date' => null);

			$is_inserted_job_ads = $this -> model_globals -> insert('job_ads', $data);
			if ($is_inserted_job_ads) {
				$this -> session -> set_flashdata('success', 'New job ads  was posted success !.');
				redirect('employers/job-ads');
			} else {
				$this -> session -> set_flashdata('error', 'New job ads  was posted fail !.');
				redirect('employers/job-ads');
			}
		}
	}

	public function modify_job_ads() {
		
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$job_key = $this -> uri -> segment(3);
		$data['title'] = "Modify Job ads";
		$data['username'] = $this -> get_name_employer();

		$this -> form_validation -> set_rules('category', 'Job Category', 'required');
		$this -> form_validation -> set_rules('location', 'Location', 'required');
		$this -> form_validation -> set_rules('job_terms', 'Job Terms', 'required');
		$this -> form_validation -> set_rules('title', 'Job Title', 'required');
		$this -> form_validation -> set_rules('date_available', 'Date Available', 'callback_available_check');
		$this -> form_validation -> set_rules('contact_person', 'Contact Person', 'required');

		if ($this -> form_validation -> run() === FALSE) {
			
			$data['job_types'] = $this -> model_globals -> select_all('job_types');
			$data['job_terms'] = $this -> model_globals -> select_all('job_term');
			$data['edu_levels'] = $this -> model_globals -> select_all('education_levels');
			$data['contact_persons'] = $this -> model_globals -> select_where('contact_persons', array('using_employer_id' => $this -> session -> userdata('employer_active_access')));

			$data['job_ads_info'] = $this -> model_globals -> select_where('job_ads', array('job_keys' => $job_key));
			if($data['job_ads_info']->num_rows()!=1){
				$this->error_404();
			}else{
				$using_job_category_id=$data['job_ads_info']->row()->using_job_sub_category_id;
				$using_main_job_category_id=$data['job_ads_info']->row()->using_job_category_id;
				
				$data['locations'] = $this -> model_globals -> select_all('job_locations');
				$categories = $this -> model_globals -> select_all('job_categories') -> result();
				$option = "";
				foreach ($categories as $category) {
					$category_id = $category -> job_category_id;
					$name = $category -> name;
					
					
					if($using_main_job_category_id.'-'.$using_job_category_id==$category_id.'-0'){
						$selected_main_category="selected";
						
					}else{
						$selected_main_category="";
					}
					
					$option .= '<option value="' . $category_id . '-0"'.$selected_main_category.' style="color:#3C8DBC;">' . $name . '</option>';
					//$option .= '<optgroup label="' . $name . '">';
					$sub_categories = $this -> model_globals -> select_where('job_sub_categories', array('using_job_category_id' => $category_id)) -> result();
					foreach ($sub_categories as $sub_category) {
						$sub_category_id = $sub_category -> job_sub_category_id;
						$sub_name = $sub_category -> name;
						
						$job_category_selected=(($category_id.'-'.$using_job_category_id)==($category_id.'-'.$sub_category_id))? 'selected':'';
						$option .= '<option value="' . $category_id . '-' . $sub_category_id . '"'.$job_category_selected.'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $sub_name . '</option>';
					}
					//$option .= '</optgroup>';
				}
				$data['categories'] = $option;
				
				$this -> load -> view(F_MASTER . "index", $data);	
			}
			
		} else {
			$date_available_input = explode("/", $this -> input -> post('date_available'));
			$date_available_db = $date_available_input[2] . "-" . $date_available_input[1] . "-" . $date_available_input[0];

			$splite_category = explode("-", $this -> input -> post('category'));
			$data = array('posted_by' => 'employer', 'using_employer_id' => $this -> session -> userdata('employer_active_access'), 'using_job_category_id' => $splite_category[0], 'using_job_sub_category_id' => $splite_category[1], 'using_job_location_id' => $this -> input -> post('location'), 'using_job_type_id' => $this -> input -> post('job_type'), 'using_contact_person_id' => $this -> input -> post('contact_person'), 'using_job_term_id' => $this -> input -> post('job_terms'), 'using_education_level_id' => $this -> input -> post('edu_level'), 'title' => $this -> input -> post('title'), 'salary' => $this -> input -> post('salary'), 'age' => $this -> input -> post('age'), 'hiring' => $this -> input -> post('num_hiring'), 'date_available' => $date_available_db, 'text_description' => $this -> input -> post('description'), 'text_requirements' => $this -> input -> post('requirement'), 'notification' => $this -> input -> post('notification'), 'gender' => $this -> input -> post('gender'), 'status' => $this -> input -> post('active'));

			$is_update_job_ads = $this -> model_globals -> update('job_ads', $data, array('job_keys' => $job_key));
			if ($is_update_job_ads) {
				$this -> session -> set_flashdata('success', 'Job ads  was modified success !.');
				redirect('employers/job-ads');
			} else {
				$this -> session -> set_flashdata('error', 'Job ads  was modified fail !.');
				redirect('employers/job-ads');
			}
		}
	}

	public function delete_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$job_key = $this -> uri -> segment(3);
		$is_deleted = $this -> model_globals -> update('job_ads',array('is_deleted'=>'YES'),array('job_keys' => $job_key));
		if ($is_deleted) {
			$this -> session -> set_flashdata('success', 'Job ads was deleted success !.');
			redirect('employers/job-ads');
		} else {
			$this -> session -> set_flashdata('error', 'Job ads  was deleted fail !.');
			redirect('employers/job-ads');
		}
	}

	public function statistics_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$job_key = $this -> uri -> segment(3);
		$data['title'] = "Manage your expired job ads";
		$data['username'] = $this -> get_name_employer();
		$job_id = $this -> model_globals -> select_string('job_ads', 'job_ads_id', array('job_keys' => $job_key));
		if($job_id=="" || $job_id==null){
			$this->error_404();
		}else{
			if($this->input->post('filter_by_date_selected') && ($this->input->post('filter_by_date_selected')=='from_to') && ($this->input->post('filter_by_date')!="")){
				$filter_statistics=$this->input->post('filter_by_date');
				$str_split_date_from_to = explode(" - ", $filter_statistics);
				$date_from = date("Y-m-d", strtotime($str_split_date_from_to[0]));
				$date_to = date("Y-m-d", strtotime($str_split_date_from_to[1]));
				
				
				$this->load->model('F-MODEL/model_employers');
				$data['statistics'] = $this -> model_employers -> select_job_statistic_filter_by_date($date_from,$date_to,$job_id);
				$this -> load -> view(F_MASTER . "index", $data);
			}else{
				$data['statistics'] = $this -> model_globals -> select_where('job_statistics', array('using_job_ads_id' => $job_id));
				$this -> load -> view(F_MASTER . "index", $data);
			}	
		}
		
		
	}

	public function renew_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$job_key = $this -> uri -> segment(3);

		$data['title'] = "Renew expired job ads";
		$this -> form_validation -> set_rules('date_available', 'Date Available', 'callback_available_check');

		if ($this -> form_validation -> run() === FALSE) {
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$date_available_input = explode("/", $this -> input -> post('date_available', TRUE));
			$date_available_db = $date_available_input[2] . "-" . $date_available_input[1] . "-" . $date_available_input[0];
			$data = array('date_available' => $date_available_db);
			$is_updated = $this -> model_globals -> update('job_ads', $data, array('job_keys' => $job_key));
			if ($is_updated) {
				$this -> session -> set_flashdata('success', 'Your expired job ads was renewed successfully!.');
				redirect('employers/job-ads');

			} else {
				$this -> session -> set_flashdata('error', 'Your expired job ads was renewed fail!.');
				redirect('employers/job-ads');
			}
		}

	}

	public function current_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Manage your job ads";

		$data['username'] = $this -> get_name_employer();
		$this -> load -> model('F-MODEL/model_employers');
		$data['current_job_ads'] = $this -> model_employers -> get_manage_current_job();
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function expired_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Manage your expired job ads";

		$data['username'] = $this -> get_name_employer();
		$this -> load -> model('F-MODEL/model_employers');
		$data['expired_job_ads'] = $this -> model_employers -> get_manage_expired_job();
		$this -> load -> view(F_MASTER . "index", $data);
	}
	public function inactive_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Manage your inactive job ads";

		$data['username'] = $this -> get_name_employer();
		$this -> load -> model('F-MODEL/model_employers');
		$data['inactive_job_ads'] = $this -> model_employers -> get_manage_inactive_job();
		$this -> load -> view(F_MASTER . "index", $data);
	}
	public function enabled_job_ads() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		
		$is_updated=$this->model_globals->update('job_ads',array('status'=>1),array('job_keys'=>$this->uri->segment(3)));
		if ($is_updated) {
			$this -> session -> set_flashdata('success', 'You have actived job selected successfully !.');
			redirect('employers/job-ads');
		} else {
			$this -> session -> set_flashdata('warning', 'You have actived job selected fail !.');
			redirect('employers/job-ads');
		}
	}

	public function job_applications() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['username'] = $this -> get_name_employer();
		$data['title'] = "Job Applications";
		$data['locations'] = $this -> model_globals -> select_all('job_locations');
		$categories = $this -> model_globals -> select_all('job_categories') -> result();
		$option = $this->get_job_category_options($categories);
		$data['categories'] = $option;
		$data['job_applications'] = $this -> model_globals -> select_join_get_only_fields('job_seeker_applied_jobs', $arr_fields = array('job_seeker_applied_job_id', 'job_seekers.first_name', 'job_seekers.last_name', 'job_ads.title', 'apply_status', 'apply_date', 'reason'), array('job_seekers' => array('using_job_seeker_id' => 'job_seeker_id'), 'job_ads' => array('using_job_ads_id' => 'job_ads_id')), $join_type = 'INNER', $arr_where = array('apply_status' => 'Pending', 'job_ads.using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "job_seeker_applied_job_id DESC");
		$data['job_approveds'] = $this -> model_globals -> select_join_get_only_fields('job_seeker_applied_jobs', $arr_fields = array('job_seeker_applied_job_id', 'job_seekers.first_name', 'job_seekers.last_name', 'job_ads.title', 'apply_status', 'apply_date', 'reason'), array('job_seekers' => array('using_job_seeker_id' => 'job_seeker_id'), 'job_ads' => array('using_job_ads_id' => 'job_ads_id')), $join_type = 'INNER', $arr_where = array('apply_status' => 'Approved', 'job_ads.using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "job_seeker_applied_job_id DESC");
		$data['job_rejecteds'] = $this -> model_globals -> select_join_get_only_fields('job_seeker_applied_jobs', $arr_fields = array('job_seeker_applied_job_id', 'job_seekers.first_name', 'job_seekers.last_name', 'job_ads.title', 'apply_status', 'apply_date', 'reason'), array('job_seekers' => array('using_job_seeker_id' => 'job_seeker_id'), 'job_ads' => array('using_job_ads_id' => 'job_ads_id')), $join_type = 'INNER', $arr_where = array('apply_status' => 'Rejected', 'job_ads.using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "job_seeker_applied_job_id DESC");
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function approved_job_apply() {
		
		$data['title']='Approved job apply';
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$job_apply_id = $this -> uri -> segment(3);

		$data['username'] = $this -> get_name_employer();
		if($this->input->post('request_reason_approved')){
			$is_updated = $this -> model_globals -> update('job_seeker_applied_jobs', array('apply_status' => 'Approved','reason'=>$this->input->post('reason')), array('job_seeker_applied_job_id' => $job_apply_id));
			if ($is_updated) {
				// send mail to jobseeker about job apply accepted
				$this->mail_employer_accepted_job_apply($job_apply_id);
				$this -> session -> set_flashdata('success', 'You have approved job selected successfully !.');
				redirect('employers/job-applications');
			} else {
				$this -> session -> set_flashdata('error', 'You have approved job selected fail !.');
				redirect('employers/job-applications');
			}
		}else{
			$this -> load -> view(F_MASTER . "index", $data);	
		}
		
	}

	public function rejected_job_apply() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title']='Rejected job apply';
		$job_apply_id = $this -> uri -> segment(3);
		$data['username'] = $this -> get_name_employer();
		if($this->input->post('request_reason_rejected')){
			$is_updated = $this -> model_globals -> update('job_seeker_applied_jobs', array('apply_status' => 'Rejected','reason'=>$this->input->post('reason')), array('job_seeker_applied_job_id' => $job_apply_id));
			if ($is_updated) {
				// send mail to jobseeker about job apply accepted 
				$this->mail_employer_rejected_job_apply($job_apply_id);
				
				$this -> session -> set_flashdata('success', 'You have rejected job selected successfully !.');
				redirect('employers/job-applications');
			} else {
				$this -> session -> set_flashdata('error', 'You have rejected job selected fail !.');
				redirect('employers/job-applications');
			}
		}else{
			$this -> load -> view(F_MASTER . "index", $data);	
		}
		
	}

	public function profile() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['username'] = $this -> get_name_employer();
		$data['title'] = "Employer Profile";
		$data['locations'] = $this -> model_globals -> select_all('job_locations');
		$categories = $this -> model_globals -> select_all('job_categories') -> result();
		$option = "";
		$option = $this->get_job_category_options($categories);
		if($this->session->userdata('is_employer_owner')){
				$data['company_info']=$this->model_globals->select_where('companies',array('using_employer_id'=>$this -> session -> userdata('is_employer_owner')));
				$data['employer_info'] = $this -> model_globals -> select_where('employers', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')));
		}else{
			
			$data['company_info']=$this->model_globals->select_where('companies',array('using_employer_id'=>$this -> session -> userdata('employer_active_access')));
			$data['employer_info'] = $this -> model_globals -> select_where('employers', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')));
		}		
		$data['employer_contact_persons'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('contact_person_id', 'username', 'contact_persons.email', 'contact_persons.status', 'name', 'phone'), array('contact_persons' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = 'contact_person_id DESC') -> result();
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function approved_job_applications() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "List approved job applications";
		$data['username'] = $this -> get_name_employer();
		$data['job_approveds'] = $this -> model_globals -> select_join_get_only_fields('job_seeker_applied_jobs', $arr_fields = array('job_seeker_applied_job_id', 'job_seekers.first_name', 'job_seekers.last_name', 'job_ads.title', 'apply_status', 'apply_date', 'reason'), array('job_seekers' => array('using_job_seeker_id' => 'job_seeker_id'), 'job_ads' => array('using_job_ads_id' => 'job_ads_id')), $join_type = 'INNER', $arr_where = array('apply_status' => 'Approved', 'job_ads.using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "job_seeker_applied_job_id DESC");
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function rejected_job_applications() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "List rejected job applications";
		$data['username'] = $this -> get_name_employer();
		$data['job_rejecteds'] = $this -> model_globals -> select_join_get_only_fields('job_seeker_applied_jobs', $arr_fields = array('job_seeker_applied_job_id', 'job_seekers.first_name', 'job_seekers.last_name', 'job_ads.title', 'apply_status', 'apply_date', 'reason'), array('job_seekers' => array('using_job_seeker_id' => 'job_seeker_id'), 'job_ads' => array('using_job_ads_id' => 'job_ads_id')), $join_type = 'INNER', $arr_where = array('apply_status' => 'Rejected', 'job_ads.using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "job_seeker_applied_job_id DESC");
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function browse_jobseekers_registered() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Employers registration";
		$data['username'] = $this -> get_name_employer();
		//$this->load->model('F-MODEL/model_employers');
		$data['jobseeker_resumes']=get_manage_jobseeker_resume_table($this->model_globals->select_all('job_seekers'),$this->uri->segment(1));
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function contact_persons() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Employers registration";
		$data['username'] = $this -> get_name_employer();
		$data['employer_info'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('employer_id', 'username', 'email', 'employers.status', 'name', 'logo', 'website', 'description', 'address', 'phone', 'fax', 'logo'), array('companies' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = 1, $sort = NULL);
		$data['employer_contact_persons'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('contact_person_id', 'username', 'contact_persons.email', 'contact_persons.status', 'name', 'phone'), array('contact_persons' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = 'contact_person_id DESC') -> result();
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function create_contact_person() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Create Employer contact person";
		$data['username'] = $this -> get_name_employer();

		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		$this -> form_validation -> set_rules('name', 'Name', 'required|min_length[2]|max_length[50]');
		$this->form_validation->set_rules('phone', 'Phone', 'required');

		if ($this -> form_validation -> run() === FALSE) {
			//$data['employers']=$this->model_globals->select_all('employers')->result();
			$data['employer_info'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('employer_id', 'username', 'email', 'employers.status', 'name', 'logo', 'website', 'description', 'address', 'phone', 'fax', 'logo'), array('companies' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = 1, $sort = NULL);
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$data_employer_contact_person = array('using_employer_id' => $this -> session -> userdata('employer_active_access'), 'email' => $this -> input -> post('email', TRUE), 'name' => $this -> input -> post('name', TRUE), 'phone' => $this -> input -> post('phone', TRUE), 'status' => 1, 'created_date' => null);

			$is_inserted_employer_contact_person = $this -> model_globals -> insert('contact_persons', $data_employer_contact_person);
			if ($is_inserted_employer_contact_person) {

				$this -> session -> set_flashdata('success', 'Your employer  contact person was created success !.');
				redirect('employers/contact-persons');

			} else {
				$this -> session -> set_flashdata('error', 'Your employer contact person  was created fail !.');
				redirect('employers/contact-person');
			}
		}
	}

	public function update_contact_person() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Update Employer Contact Person";

		$employer_contact_person_id = $this -> uri -> segment(3);
		$data['username'] = $this -> get_name_employer();

		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		$this -> form_validation -> set_rules('name', 'Name', 'required|min_length[2]|max_length[50]');
		$this->form_validation->set_rules('phone', 'Phone', 'required');

		if ($this -> form_validation -> run() === FALSE) {
			$data['employer_contact_person'] = $this -> model_globals -> select_where('contact_persons', array('contact_person_id' => $employer_contact_person_id)) -> result();
			if($data['employer_contact_person']==null){
				$this->error_404();
			}else{
				//$data['employers']=$this->model_globals->select_all('employers')->result();
				$data['employer_info'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('employer_id', 'username', 'email', 'employers.status', 'name', 'logo', 'website', 'description', 'address', 'phone', 'fax', 'logo'), array('companies' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = 1, $sort = NULL);
				$this -> load -> view(F_MASTER . "index", $data);	
			}
			
		} else {
			$data_employer_contact_person = array('using_employer_id' => $this -> session -> userdata('employer_active_access'), 'email' => $this -> input -> post('email', TRUE), 'name' => $this -> input -> post('name', TRUE), 'phone' => $this -> input -> post('phone', TRUE));

			$is_updated_employer_contact_person = $this -> model_globals -> update('contact_persons', $data_employer_contact_person, array('contact_person_id' => $employer_contact_person_id));
			if ($is_updated_employer_contact_person) {

				$this -> session -> set_flashdata('success', 'Employer  contact person was updated success !.');
				redirect('employers/contact-persons');

			} else {
				$this -> session -> set_flashdata('error', 'Employer contact person  was updated fail !.');
				redirect('employers/contact-persons');
			}
		}
	}

	public function delete_contact_person() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$employer_contact_person_id = $this -> uri -> segment(3);
		$is_deleted = $this -> model_globals -> delete('contact_persons', array('contact_person_id' => $employer_contact_person_id));
		if ($is_deleted) {
			$this -> session -> set_flashdata('success', 'Employer contact person information was deleted success !.');
			redirect('employers/contact-persons');
		} else {
			$this -> session -> set_flashdata('error', 'Employer contact person information  was deleted fail !.');
			redirect('employers/contact-persons');
		}
	}

	public function edit_profile() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Edit Profile";
		$employer_id = $this -> session -> userdata('employer_active_access');
		$data['username'] = $this -> get_name_employer();
		$this -> form_validation -> set_rules('username', 'Username', 'required');
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		$this -> form_validation -> set_rules('company', 'company', 'required|min_length[2]|max_length[50]');

		if ($this -> form_validation -> run() === FALSE) {
			if($this->session->userdata('is_employer_owner')){
					$data['company_info']=$this->model_globals->select_where('companies',array('using_employer_id'=>$this -> session -> userdata('is_employer_owner')));
					$data['employer_info'] = $this -> model_globals -> select_where('employers', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')));
			}else{
				
				$data['company_info']=$this->model_globals->select_where('companies',array('using_employer_id'=>$this -> session -> userdata('employer_active_access')));
				$data['employer_info'] = $this -> model_globals -> select_where('employers', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')));
			}		
			$this -> load -> view(F_MASTER . "index", $data);
		} else {

			$token_key = "";
			$data_employer = array('username' => $this -> input -> post('username', TRUE), 'email' => $this -> input -> post('email', TRUE)
			//'password'=>sha1($this->input->post('password',TRUE))
			//'subscribe'=>$this->input->post('subscribe',TRUE),
			//'is_sub_account'=>'NO',
			//'using_sub_account_of_employer'=>0,
			//'status'=>1,
			//'token_key'=>$token_key,
			//'created_date'=>null
			);

			$is_updated_employer = $this -> model_globals -> update('employers', $data_employer, array('employer_id' => $employer_id));

			$data_company = array(
				//'using_employer_id'=>$is_inserted_employer_with_return_id,
				'name' => $this -> input -> post('company', TRUE), 'description' => $this -> input -> post('company_desc', TRUE), 'address' => $this -> input -> post('address', TRUE), 'phone' => $this -> input -> post('phone', TRUE), 'fax' => $this -> input -> post('fax', TRUE), 'website' => $this -> input -> post('website', TRUE)
				//'status'=>1,
				//'created_date'=>null
				);
				if($this -> session -> userdata('is_employer_owner')){
					$is_updated_company = $this -> model_globals -> update('companies', $data_company, array('using_employer_id' =>$this -> session -> userdata('is_employer_owner')));	
				}else{
					$is_updated_company = $this -> model_globals -> update('companies', $data_company, array('using_employer_id' =>$employer_id));
				}
				
				if (!$is_updated_company && !$is_updated_employer) {

					$this -> session -> set_flashdata('error', 'Your  information was updated fail !.');
					redirect('employers/profile');
				}else{
					
					$this -> session -> set_flashdata('success', 'Your information was updated success !.');
					redirect('employers/profile');	
				}

		}
	}

	public function change_password() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Change Password";
		$data['username'] = $this -> get_name_employer();
		$this -> form_validation -> set_rules('password', 'Password', 'required|matches[conf_password]|min_length[6]|max_length[50]');
		$this -> form_validation -> set_rules('conf_password', 'Password Confirmation', 'required|min_length[6]|max_length[50]');

		if ($this -> form_validation -> run() === FALSE) {
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$data = array('password' => sha1($this -> input -> post('password', TRUE)));

			$is_updated = $this -> model_globals -> update("employers", $data, array("employer_id" => $this -> session -> userdata('employer_active_access')));
			if ($is_updated) {
				$this -> session -> set_flashdata('success', "You have changed your password success !");
				redirect('employers/change-password');
			} else {
				$this -> session -> set_flashdata('error', "You have changed your password fail !");
				redirect('employers/change-password');
			}
		}
	}

	public function manage_sub_account() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Employer manage sub account";
		$data['username'] = $this -> get_name_employer();
		$data['sub_accounts'] = $this -> model_globals -> select_where('employers', array('using_sub_account_of_employer' => $this -> session -> userdata('employer_active_access'))) -> result();
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function create_sub_account() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Create a new sub account";
		$data['username'] = $this -> get_name_employer();
		$this -> form_validation -> set_rules('username', 'Username', 'required');
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email|is_unique[employers.email]');
		$this->form_validation->set_rules('mobile', 'mobile', 'required');
		$this -> form_validation -> set_rules('password', 'Password', 'required|matches[conf_password]|min_length[6]|max_length[50]');
		$this -> form_validation -> set_rules('conf_password', 'Password Confirmation', 'required|min_length[6]|max_length[50]');

		if ($this -> form_validation -> run() === FALSE) {
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$token_key = "";
			$data_employer = array('username' => $this -> input -> post('username', TRUE), 'email' => $this -> input -> post('email', TRUE), 'password' => sha1($this -> input -> post('password', TRUE)), 'mobile' => $this -> input -> post('mobile', TRUE), 'is_sub_account' => 'YES', 'using_sub_account_of_employer' => $this -> session -> userdata('employer_active_access'), 'status' => 1, 'token_key' => $token_key, 'created_date' => null);

			$is_inserted_employer_with_return_id = $this -> model_globals -> insert_get_last_id('employers', $data_employer);

			if ($is_inserted_employer_with_return_id) {
				$modules = $this -> model_globals -> select_all('employer_modules');
				foreach ($modules->result() as $module) {
					$module_id = $module -> employer_module_id;
					$this -> model_globals -> insert('employer_module_permissions', array('using_employer_id' => $is_inserted_employer_with_return_id, 'using_employer_module_id' => $module_id, 'is_access' => 'NO', 'status' => 1, 'created_date' => null));
				}
				$this -> session -> set_flashdata('success', 'The new sub account has been created successfully!');
				redirect('employers/manage-sub-account');

			} else {
				$this -> session -> set_flashdata('error', 'The new sub account has been created fail!');
				redirect('employers/manage-sub-account');
			}
		}
	}

	public function update_sub_account() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}

		$data['title'] = "Create a new sub account";
		$data['username'] = $this -> get_name_employer();
		$sub_account_id = $this -> uri -> segment(3);
		$this -> form_validation -> set_rules('username', 'Username', 'required');
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		$this->form_validation->set_rules('mobile', 'Mobile', 'required');
		$this -> form_validation -> set_rules('password', 'Password', 'matches[conf_password]');
		//$this -> form_validation -> set_rules('conf_password', 'Password Confirmation', 'required');

		if ($this -> form_validation -> run() === FALSE) {
			$data['employer_sub_info'] = $this -> model_globals -> select_where('employers', array('employer_id' => $sub_account_id));
			if($data['employer_sub_info']->num_rows!=1){
				$this->error_404();
			}else{
				$this -> load -> view(F_MASTER . "index", $data);	
			}
			
		} else {
			$token_key = "";
			if($this->input->post('password',TRUE)==""){
				$data_employer = array('username' => $this -> input -> post('username', TRUE), 'email' => $this -> input -> post('email', TRUE), 'mobile' => $this -> input -> post('mobile', TRUE));	
			}else{
				$data_employer = array('username' => $this -> input -> post('username', TRUE), 'email' => $this -> input -> post('email', TRUE), 'password' => sha1($this -> input -> post('password', TRUE)), 'mobile' => $this -> input -> post('mobile', TRUE));
			}
			
			$is_updated_sub_account = $this -> model_globals -> update('employers', $data_employer, array('employer_id' => $sub_account_id));

			if ($is_updated_sub_account) {
				$this -> session -> set_flashdata('success', 'The sub account has been updated successfully!');
				redirect('employers/manage-sub-account');

			} else {
				$this -> session -> set_flashdata('error', 'The sub account has been updated fail!');
				redirect('employers/manage-sub-account');
			}
		}
	}

	public function delete_sub_account() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$sub_account_id = $this -> uri -> segment(3);
		$is_deleted = $this -> model_globals -> delete('employers', array('employer_id' => $sub_account_id));
		if ($is_deleted) {
			$this -> session -> set_flashdata('success', 'Sub account selected was deleted success !.');
			redirect('employers/manage-sub-account');
		} else {
			$this -> session -> set_flashdata('error', 'Sub account selected was deleted fail !.');
			redirect('employers/manage-sub-account');
		}
	}

	public function modify_sub_account_permissions($author_id = 0) {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Manage the sub account permissions";
		$data['username'] = $this -> get_name_employer();
		if (!$this -> input -> post('modules')) {
			$main_modules = $this -> model_globals -> select_all('employer_main_modules') -> result();
			$option = "";
			foreach ($main_modules as $main_module) {
				$main_module_id = $main_module -> employer_main_module_id;
				$name = $main_module -> name;
				$option .= '<div class="col-md-12 clear"><b>' . $name . '</b></div>';

				$sub_modules = $this -> model_globals -> select_join('employer_module_permissions', array('employer_modules' => array('using_employer_module_id' => 'employer_module_id')), 'inner', array('using_employer_main_module_id' => $main_module_id, 'using_employer_id' => $author_id));
				
				foreach ($sub_modules->result() as $sub_module) {
					$module_permission_id = $sub_module -> employer_module_permissions_id;
					$sub_name = $sub_module -> name;
					$is_access = $sub_module -> is_access;
					$is_checked = ($is_access == "YES") ? "checked" : '';
					$option .= '<div class="col-md-6 clear"><input type="checkbox" name="modules[]" value="' . $module_permission_id . '"' . $is_checked . ' />&nbsp;' . $sub_name . '</div>';
					//$option.='<option value="'.$category_id.'-'.$sub_category_id.'">'.$sub_name.'</option>';
				}

			}

			$data['modules'] = $option;
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			$access_module_permissions = $this -> input -> post('modules');
			$this -> load -> model('F-MODEL/model_employers');
			$this -> model_employers -> update_access_permission($access_module_permissions, $author_id);
			$this -> model_employers -> update_not_access_permission($access_module_permissions, $author_id);
			redirect('employers/manage-sub-account');
		}

	}

	public function view_profile() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "View Profile";
		$data['employer_info'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('employer_id', 'username', 'email', 'employers.status', 'name', 'logo', 'website', 'description', 'address', 'phone', 'fax', 'logo'), array('companies' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', $arr_where = array('employer_id' => $this -> session -> userdata('employer_active_access')), $limit = 1, $sort = NULL);
		$this -> load -> view(F_MASTER . "index", $data);
	}

	public function change_picture() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Change profile picture";
		if ($this -> input -> post('checking')) {

			$config['upload_path'] = './Templates/F-Template/F-IMAGES/employer_profile/';
			$config['allowed_types'] = 'gif|jpg|jpeg|png';
			$config['max_size'] = '30000';
			$this -> load -> library('upload', $config);

			if (!$this -> upload -> do_upload()) {
				$data['errors']= array('error' => $this->upload->display_errors());
				$this -> load -> view(F_MASTER . "index", $data);
			} else {

				$data = $this -> upload -> data();
				$image_name = $data['file_name'];

				$img_width = $data['image_width'];
				$img_height = $data['image_height'];

				$scale_height = 120 / $img_height;
				$fit_width = $img_width * $scale_height;
				$fit_height = $img_height * $scale_height;

				$config['image_library'] = 'gd2';
				$config['source_image'] = "./Templates/F-Template/F-IMAGES/employer_profile/$image_name";
				$config['create_thumb'] = TRUE;
				$config['maintain_ratio'] = TRUE;
				$config['width'] = $fit_width;
				$config['height'] = $fit_height;

				$this -> load -> library('image_lib', $config);

				$this -> image_lib -> resize();
				if (!$this -> image_lib -> resize()) {
					echo $this -> image_lib -> display_errors();
					exit ;
				}

				//$logo_path = "templates/back_end/images/";
				$rs = $this -> model_globals -> update('employers', array('photo_profile' => $image_name), array('employer_id' => $this -> session -> userdata('employer_active_access')));
				if ($rs) {
					$this -> session -> set_flashdata('success', 'Your picture profile was modified success .');
					redirect('employers/change-picture');
				} else {
					$this -> session -> set_flashdata('error', 'Your picture profile was modified fail !');
					redirect('employers/change-picture');
				}
			}
		} else {
			$this -> load -> view(F_MASTER . "index", $data);
		}
	}

	public function modify_logo() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Modify Logo";
		$data['username'] = $this -> get_name_employer();
		if ($this -> input -> post('checking')) {

			$config['upload_path'] = './Templates/F-Template/F-IMAGES/employer_logo/';
			$config['allowed_types'] = 'gif|jpg|jpeg|png';
			$config['max_size'] = '30000';
			$this -> load -> library('upload', $config);

			if (!$this -> upload -> do_upload()) {
				$data['errors']= array('error' => $this->upload->display_errors());
				$this -> load -> view(F_MASTER . "index", $data);
			} else {

				$data = $this -> upload -> data();
				$image_name = $data['file_name'];

				$img_width = $data['image_width'];
				$img_height = $data['image_height'];

				$scale_height = 120 / $img_height;
				$fit_width = $img_width * $scale_height;
				$fit_height = $img_height * $scale_height;

				$config['image_library'] = 'gd2';
				$config['source_image'] = "./Templates/F-Template/F-IMAGES/employer_logo/$image_name";
				$config['create_thumb'] = TRUE;
				$config['maintain_ratio'] = TRUE;
				$config['width'] = $fit_width;
				$config['height'] = $fit_height;

				$this -> load -> library('image_lib', $config);

				$this -> image_lib -> resize();
				if (!$this -> image_lib -> resize()) {
					echo $this -> image_lib -> display_errors();
					exit ;
				}

				//$logo_path = "templates/back_end/images/";
				$rs = $this -> model_globals -> update('companies', array('logo' => $image_name), array('using_employer_id' => $this -> session -> userdata('employer_active_access')));
				if ($rs) {
					$this -> session -> set_flashdata('success', 'Your logo was modified success .');
					redirect('employers/modify-logo');
				} else {
					$this -> session -> set_flashdata('error', 'Your logo was modified fail !');
					redirect('employers/modify-logo');
				}
			}
		} else {
			$this -> load -> view(F_MASTER . "index", $data);
		}
	}

	public function messages() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Messages";
		$data['username'] = $this -> get_name_employer();
		$this -> load -> view(F_MASTER . "index", $data);
	}
	public function featured_job_ads(){
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Confirm add to featured job";
		$data['username'] = $this -> get_name_employer();
		if($this->input->post('featured_job_id')){
			$job_key= $this->input->post('featured_job_id');
			$is_updated=$this->model_globals->update('job_ads',array('is_featured_job'=>'YES'),array('job_keys'=>$job_key));
			if ($is_updated) {
				$this -> session -> set_flashdata('success', "Your  have been added job selected to featured job  success !");
				redirect('employers/current-job-ads');
			} else {
				$this -> session -> set_flashdata('error', "Your  have been added job selected to featured job  fail !");
				redirect('employers/current-job-ads');
			}
		}else{
			$this -> load -> view(F_MASTER . "index", $data);	
		}
		
	}

	public function banners() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "banners";
		$data['username'] = $this -> get_name_employer();
		$data['banners']= $this -> model_globals -> select_join_get_only_fields('employer_banners', $arr_fields = array('banner_areas.name AS area', 'employer_banners.status', '', 'employer_banners.created_date','img_name', 'employer_banners.name AS banner_name', 'employer_banner_id'), array('banner_areas' => array('using_banner_area_id' => 'banner_area_id')), $join_type = 'INNER', $arr_where = array('using_employer_id' => $this -> session -> userdata('employer_active_access')), $limit = NULL, $sort = "employer_banner_id DESC");
		$this -> load -> view(F_MASTER . "index", $data);
	}
	public function create_new_banner() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Create new banner";
		$data['username'] = $this -> get_name_employer();
		$this -> form_validation -> set_rules('name', 'Name', 'required');
		//$this -> form_validation -> set_rules('image', 'Image', 'required');
		$this -> form_validation -> set_rules('link', 'Link', 'required');
		
		if ($this -> form_validation -> run() === FALSE) {
			$data['link_types']=$this->model_globals->select_all('link_types');
			$data['banner_areas']=$this->model_globals->select_all('banner_areas');
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			
			$config['upload_path'] = './Templates/F-Template/F-IMAGES/employer_banner/';
			$config['allowed_types'] = 'gif|jpg|jpeg|png';
			$config['max_size'] = '30000';
			$this -> load -> library('upload', $config);

			if (!$this -> upload -> do_upload()) {
				$data['errors']= array('error' => $this->upload->display_errors());
				$this -> load -> view(F_MASTER . "index", $data);
			} else {

				$data = $this -> upload -> data();
				$image_name = $data['file_name'];

				$img_width = $data['image_width'];
				$img_height = $data['image_height'];

				$scale_height = 120 / $img_height;
				$fit_width = $img_width * $scale_height;
				$fit_height = $img_height * $scale_height;

				$config['image_library'] = 'gd2';
				$config['source_image'] = "./Templates/F-Template/F-IMAGES/employer_banner/$image_name";
				$config['create_thumb'] = TRUE;
				$config['maintain_ratio'] = TRUE;
				$config['width'] = $fit_width;
				$config['height'] = $fit_height;

				$this -> load -> library('image_lib', $config);

				$this -> image_lib -> resize();
				if (!$this -> image_lib -> resize()) {
					echo $this -> image_lib -> display_errors();
					exit ;
				}
				$AvailableDate=Date('Y-m-d', strtotime("+30 days"));
			
				$data = array('using_employer_id' =>$this->session->userdata('employer_active_access'),'using_link_type_id'=>$this->input->post('link_type',TRUE),'name'=>$this->input->post('name',TRUE),'img_name'=>$image_name,'link'=>$this->input->post('link',TRUE),'using_banner_area_id'=>$this->input->post('areas',TRUE),'available_date'=>$AvailableDate,'created_date'=>null,'status'=>1);
	
				$is_inserted = $this -> model_globals -> insert("employer_banners", $data);
				if ($is_inserted) {
					$this -> session -> set_flashdata('success', "Your banner have been created  success !");
					redirect('employers/banners');
				} else {
					$this -> session -> set_flashdata('error', "Your banner have been created  fail !");
					redirect('employers/banners');
				}
			}
			
		}
	}
	public function update_banner() {
		$banner_id=$this->uri->segment(3);
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Update banner";
		$data['username'] = $this -> get_name_employer();
		$this -> form_validation -> set_rules('name', 'Name', 'required');
		//$this -> form_validation -> set_rules('image', 'Image', 'required');
		$this -> form_validation -> set_rules('link', 'Link', 'required');
		
		if ($this -> form_validation -> run() === FALSE) {
			$data['link_types']=$this->model_globals->select_all('link_types');
			$data['banner_areas']=$this->model_globals->select_all('banner_areas');
			$data['banner']= $this -> model_globals -> select_where('employer_banners',array('employer_banner_id'=>$banner_id));
			if($data['banner']->num_rows()!=1){
				$this->error_404();
			}else{
				$this -> load -> view(F_MASTER . "index", $data);	
			}
			
		} else {
			$image_name="";
			$error_upload=FALSE;
			if (!empty($_FILES['userfile']['name'])){
				$config['upload_path'] = './Templates/F-Template/F-IMAGES/employer_banner/';
				$config['allowed_types'] = 'gif|jpg|jpeg|png';
				$config['max_size'] = '30000';
				$this -> load -> library('upload', $config);
	
				if (!$this -> upload -> do_upload()) {
					$data['errors']= array('error' => $this->upload->display_errors());
					$error_upload=TRUE;
					$this -> load -> view(F_MASTER . "index", $data);
				} else {
	
					$data = $this -> upload -> data();
					$image_name = $data['file_name'];
	
					$img_width = $data['image_width'];
					$img_height = $data['image_height'];
	
					$scale_height = 120 / $img_height;
					$fit_width = $img_width * $scale_height;
					$fit_height = $img_height * $scale_height;
	
					$config['image_library'] = 'gd2';
					$config['source_image'] = "./Templates/F-Template/F-IMAGES/employer_banner/$image_name";
					$config['create_thumb'] = TRUE;
					$config['maintain_ratio'] = TRUE;
					$config['width'] = $fit_width;
					$config['height'] = $fit_height;
	
					$this -> load -> library('image_lib', $config);
	
					$this -> image_lib -> resize();
					if (!$this -> image_lib -> resize()) {
						echo $this -> image_lib -> display_errors();
						exit ;
					}
				}
			}
			
			if($image_name!=""){
				$data = array('using_link_type_id'=>$this->input->post('link_type',TRUE),'name'=>$this->input->post('name',TRUE),'img_name'=>$image_name,'link'=>$this->input->post('link',TRUE),'using_banner_area_id'=>$this->input->post('areas',TRUE));
			}else{
				$data = array('using_link_type_id'=>$this->input->post('link_type',TRUE),'name'=>$this->input->post('name',TRUE),'link'=>$this->input->post('link',TRUE),'using_banner_area_id'=>$this->input->post('areas',TRUE));
			}
			
			if($error_upload!=TRUE){
				$is_updated = $this -> model_globals -> update("employer_banners", $data,array('employer_banner_id'=>$banner_id));
				if ($is_updated) {
					$this -> session -> set_flashdata('success', "Your banner have been updated  success !");
					redirect('employers/banners');
				} else {
					$this -> session -> set_flashdata('error', "Your banner have been updated  fail !");
					redirect('employers/banners');
				}
			}

		}
	}
	public function renew_banner(){
		$data['title']='Renew Banner';
		$banner_id=$this->uri->segment(3);
		$data['username'] = $this -> get_name_employer();
		
		if($this->input->post('banner_package')){
			$package=$this->input->post('banner_package');
			// add 3 days to date
			$AvailableDate=Date('Y-m-d', strtotime("+$package days"));
			$data=array('available_date'=>$AvailableDate,'status'=>0);
			$is_updated = $this -> model_globals -> update("employer_banners", $data,array('employer_banner_id'=>$banner_id));
			if ($is_updated) {
				$this -> session -> set_flashdata('success', "Your banner have been renewed  success !");
				redirect('employers/banners');
			} else {
				$this -> session -> set_flashdata('error', "Your banner have been renewed  fail !");
				redirect('employers/banners');
			}
		}else{
			$this -> load -> view(F_MASTER . "index", $data);
		}
	}
	public function delete_banner() {
		$banner_id=$this->uri->segment(3);
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
			$is_deleted = $this -> model_globals -> delete("employer_banners", array('employer_banner_id'=>$banner_id));
			if ($is_deleted) {
				$this -> session -> set_flashdata('success', "Your banner have been deleted  success !");
				redirect('employers/banners');
			} else {
				$this -> session -> set_flashdata('error', "Your banner have been deleted  fail !");
				redirect('employers/banners');
			}
	}

	public function download_jobseeker_resume() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$using_seeker_id = $this -> uri -> segment(3);
		$file_name=$this->model_globals->select_string("seeker_documents",'file_name',$arr_item_where = array('using_seeker_id'=>$using_seeker_id,'is_resume'=>"YES"));
		//$file_name = $query_file_info->row()->file_name;
		if($file_name =="" || $file_name==null){
			$this->error_404();
		}else{
			$this -> load -> helper('download');
			$data = file_get_contents("./Templates/F-Template/F-DOCS/seeker_documents/" . $file_name);
			// Read the file's contents
			//$name = 'myphoto.jpg';
	
			force_download($file_name, $data);	
		}
	}

	public function video_presentation() {
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "Video Presentation";
		$data['username'] = $this -> get_name_employer();
		if ($this -> input -> post('checking')) {

			$config['upload_path'] = './Templates/F-Template/F-VIDEOS/employer_video_presentation/';
			$config['allowed_types'] = 'avi|flv|wmv|mp3';
			$config['max_size'] = '10240';
			$this -> load -> library('upload', $config);

			if (!$this -> upload -> do_upload()) {
				$data['errors']= array('error' => $this->upload->display_errors());
				$this -> load -> view(F_MASTER . "index", $data);
			} else {

				$data = $this -> upload -> data();
				$video_name = $data['file_name'];

				//$logo_path = "templates/back_end/images/";
				$rs = $this -> model_globals -> update('companies', array('video_presentation' => $video_name), array('using_employer_id' => $this -> session -> userdata('employer_active_access')));
				if ($rs) {
					$this -> session -> set_flashdata('success', 'Your video presentation was modified success .');
					redirect('employers/video-presentation');
				} else {
					$this -> session -> set_flashdata('error', 'Your video presentation was modified fail !');
					redirect('employers/video-presentation');
				}
			}
		} else {
			$this -> load -> view(F_MASTER . "index", $data);
		}
	}
	
	public function send_mail_to_jobseeker(){
		$jobseeker_id=$this->input->post('jobseeker_id');
		$message=$this->input->post('message');
		//send mail and redirect
	}
	public function logout() {
		$this -> session -> sess_destroy();
		redirect('employers/login');
		//$this->load->view(F_MASTER."index",$data);
	}

	public function get_name_employer() {
		$username = $this -> model_globals -> select_string("employers", "username", array('employer_id' => $this -> session -> userdata('employer_active_access')));
		return ucfirst($username);
	}

	function isExist($job_key) {
		if (!$this -> model_globals -> check_data_exist("job_ads", array("job_keys" => $job_key))) {
			return FALSE;
		} else {
			return TRUE;
		}
	}
	public function available_check($date_available){
		
		$date_available_input = explode("/", $date_available);
		$date_available_db = $date_available_input[0] . "-" . $date_available_input[1] . "-" . $date_available_input[2];
		
		$cur=date('d-m-Y');
		
		$curdate=strtotime($cur);
		$mydate=strtotime($date_available_db);
		
		
		if($curdate >$mydate)
		{
			
		    $this -> form_validation -> set_message('available_check', 'Your date available is invalid !');
			return FALSE;
		}
		return TRUE;
	}
	public function no_permission(){
		if (!$this -> session -> userdata('employer_active_access')) {
			redirect("employers/login");
		}
		$data['title'] = "No permission";
		$data['username'] = $this -> get_name_employer();
		$this -> load -> view(F_MASTER . "index", $data);
	}
	public function compose_mail_to_jobseeker(){
		$jobseeker_id=$this->input->post('to_jobseeker');
		$employer_id=$this->session->userdata('employer_active_access');
		$subject=$this->input->post('subject');
		$message=$this->input->post('message');
		
		$mail_from_employer=$this->model_globals->select_string('employers','email',array('employer_id'=>$employer_id));
		$mail_to_jobseeker=$this->model_globals->select_string('job_seekers','email',array('job_seeker_id'=>$jobseeker_id));
		
		$is_compose_mail_sent=$this->employer_send_mail_to_jobseeker($mail_from_employer,$mail_to_jobseeker,$subject,$message);
		
		if($is_compose_mail_sent){
			$this -> session -> set_flashdata('success', 'Your message was sent to jobseeker selected success !');
			redirect('employers/browse-jobseekers-registered');
		}else{
			$this -> session -> set_flashdata('error', 'Your message was sent to jobseeker selected fail !.Please try again.');
			redirect('employers/browse-jobseekers-registered');
		}
	}
	
	/*+++++++++++++++++Send mail++++++++++++++++++*/
	public function send_mail_to_employer_activation_account($activation_key,$email){
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$message="Dear $email,<br />
						<p>You or someone with your email id signed up at jobpending.com website,Your new account is almost ready, but before you can login you need to confirm your email id by visiting the link below:<br />
						<a href='".base_url()."employers/activation-account/".$activation_key."'>".base_url()."employers/activation-account/".$activation_key."</a></p>
						
						<p>One you have visited the verification URL, your account will be activated.</p>
						
						</p>if you have any problems or questions, Please reply to this email.</p>
						
						</p>Best regards,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($email); 
		$this->email->cc('jobpending.info@gmail.com');  
		//$this->email->bcc('them@their-example.com'); 
		
		$this->email->subject('Jobpending activation account');
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}
	
	public function send_mail_to_employer_reset_password($key_active_password,$email){
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$message="Dear Sir/Madam,<br />

				<p>We've sent this message because you have requested that your jobpending password to be reset.</br />
				To get back into your jobpending accout you will need to create a new password.</p>
				
				<p>-------------------------------------------------------</p>
				<p>Here's how you do that <br />
				1.Click the link below to open a new and secure browser window.<br />
				2.Enter the requested information and follow the instruction to reset your password.</p>
				
				<p>Reset your password now:<br />
				<a href='".base_url()."employers/activation-forgotten-password/".$key_active_password."'>".base_url()."employers/activation-forgotten-password/".$key_active_password."</a></p>
				
				</p>Best regard,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
				
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($email); 
		$this->email->cc('jobpending.info@gmail.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$this->email->subject('Jobpending reset  account password');
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}
	
	public function send_mail_to_employer_resend_activate_account($activation_key,$email){
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$message="Dear $email,<br />
						<p>You or someone with your email id signed up at jobpending.com website have requested to resent activate account,Your new account is almost ready, but before you can login. You need to confirm your email id by visiting the link below:<br />
						<a href='".base_url()."employers/activation-account/".$activation_key."'>".base_url()."employers/activation-account/".$activation_key."</a></p>
						
						<p>One you have visited the verification URL, your account will be activated.</p>
						
						<p>if you have any problems or questions, Please reply to this email.</p>
						
						<p>Best regard,</p>
						<p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($email); 
		$this->email->cc('jobpending.info@gmail.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$this->email->subject('Jobpending activation account');
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	
	}
	public function employer_send_mail_to_jobseeker($mail_from_employer,$mail_to_jobseeker,$subject,$message){
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$this->email->from($mail_from_employer,$mail_from_employer);
		$this->email->to($mail_to_jobseeker); 
		//$this->email->cc('jobs@jobpending.com'); 
		//$this->email->bcc('them@their-example.com'); 
		$message.="</p>if you have any problems or questions, Please reply to this email or contact to jobpending team.</p>
						
						</p>Best regard,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
		
		$this->email->subject($subject);
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}
	
	public function mail_employer_accepted_job_apply($job_apply_id){
		$this->load->model('F-MODEL/model_employers');
		$job_info=$this->model_employers->is_job_post_by_sub_account($job_apply_id);
		if($job_info->row()->is_sub_account=="YES"){
			$employer_id=$job_info->row()->using_sub_account_of_employer;
		}else{
			$employer_id=$job_info->row()->employer_id;
		}
		$job_seeker_id=$job_info->row()->using_job_seeker_id;
		$title=$job_info->row()->title;
		
		$contact_name=$job_info->row()->contact_name;
		$contact_email=$job_info->row()->contact_email;
		$contact_phone=$job_info->row()->contact_phone;
		
		$company_name=$this->model_globals->select_string("companies",'name',array('using_employer_id'=>$employer_id));
		$jobseeker_info=$this->model_globals->select_where("job_seekers" ,array('job_seeker_id'=>$job_seeker_id));
		$job_seeker_email=$jobseeker_info->row()->email;
		$job_seeker_fname=$jobseeker_info->row()->first_name;
		$job_seeker_lname=$jobseeker_info->row()->last_name;
		// mail process
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($job_seeker_email); 
		//$this->email->cc('jobs@jobpending.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$subject=$company_name." accepted job apply on position ".$title;
		$message="Dear $job_seeker_fname. $job_seeker_lname,<br />
						<p>We would like to confirm you about job that you have applied to $company_name as the position $title.</p>
						<p>Now  $company_name company that you have applied job as the position $title has been accpeted your job apply online from jobpending.com website.<br />
							So,Please login to your account on website jobpending.com that you have registed to see detail information about it, or contact direct to comapny contact below :<br />
							Contact Name: $contact_name<br />
							Contact Email: $contact_email<br />
							Contact Phone: $contact_phone
							  
						</p>
						
						</p>if you have any problems or questions, Please reply to this email.</p>
						
						</p>Best regard,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
						
		$this->email->subject($subject);
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}
	
	public function mail_employer_rejected_job_apply($job_apply_id){
		$this->load->model('F-MODEL/model_employers');
		$job_info=$this->model_employers->is_job_post_by_sub_account($job_apply_id);
		if($job_info->row()->is_sub_account=="YES"){
			$employer_id=$job_info->row()->using_sub_account_of_employer;
		}else{
			$employer_id=$job_info->row()->employer_id;
		}
		$job_seeker_id=$job_info->row()->using_job_seeker_id;
		$title=$job_info->row()->title;
		
		$contact_name=$job_info->row()->contact_name;
		$contact_email=$job_info->row()->contact_email;
		$contact_phone=$job_info->row()->contact_phone;
		
		$company_name=$this->model_globals->select_string("companies",'name',array('using_employer_id'=>$employer_id));
		$jobseeker_info=$this->model_globals->select_where("job_seekers" ,array('job_seeker_id'=>$job_seeker_id));
		$job_seeker_email=$jobseeker_info->row()->email;
		$job_seeker_fname=$jobseeker_info->row()->first_name;
		$job_seeker_lname=$jobseeker_info->row()->last_name;
		// mail process
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($job_seeker_email); 
		//$this->email->cc('jobs@jobpending.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$subject=$company_name." rejected job apply on position ".$title;
		$message="Dear $job_seeker_fname. $job_seeker_lname,<br />
						<p>We would like to confirm you about job that you have apply to $company_name as the position $title.</p>
						<p>Now  $company_name company that you have applied job as the position $title have been rejected your job apply online from jobpending.com website.<br />
							So,Please login to your account on website jobpending.com that you have registed to see detail information about it.
							  
						</p>
						
						</p>if you have any problems or questions, Please reply to this email.</p>
						
						</p>Best regard,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
						
		$this->email->subject($subject);
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}
	
	/*++++++++++++++++Ajax Request++++++++++++++++*/
	
	public function jobseeker_seeking_rule_description(){
		$jobseeker_id=$this->input->post('jobseeker_id');
		$brifly_desc=$this->model_globals->select_string('job_seekers_job_preference','briefly_description',array('using_job_seeker_id'=>$jobseeker_id));
		echo $brifly_desc;
		
	}
	public function jobseeker_seeking_rule_category(){
		$jobseeker_id=$this->input->post('jobseeker_id');
		
		$pre_categories="";
		$get_prefer_categories=$this->model_globals->select_join_get_only_fields('job_preference_categories', $arr_fields = array('name'),$arr_join = array('job_sub_categories'=> array('using_job_sub_category_id' => 'job_sub_category_id')), $join_type = 'INNER', $arr_where = array('using_job_seeker_id'=>$jobseeker_id,'is_prefered'=>'YES'), $limit = NULL,$sort=NULL);
		$i=1;
		foreach($get_prefer_categories->result() as $category){
			$pre_categories.=$category->name;
			if($get_prefer_categories->num_rows()!=$i){
				$pre_categories.="<b> , </b>";
			}
			$i++;
		}
		
		echo $pre_categories;
	}
	public function jobseeker_seeking_rule_location(){
		$jobseeker_id=$this->input->post('jobseeker_id');
		$pre_locations="";
		$get_prefer_locations=$this->model_globals->select_join_get_only_fields('job_preference_locations', $arr_fields = array('name'),$arr_join = array('job_locations'=> array('using_location_id' => 'job_location_id')), $join_type = 'INNER', $arr_where = array('using_job_seeker_id'=>$jobseeker_id,'is_prefered'=>'YES'), $limit = NULL,$sort=NULL);
		$j=1;
		foreach($get_prefer_locations->result() as $location){
			$pre_locations.=$location->name;
			if($get_prefer_locations->num_rows()!=$j){
				$pre_locations.="<b> , </b>";
			}
			$j++;
		}
		echo $pre_locations;
		
	}	
	public function get_job_category_options($categories){
		$option='';
		foreach ($categories as $category) {
			$category_id = $category -> job_category_id;
			$name = $category -> name;
			//$option .= '<optgroup label="' . $name . '">';
			$option .= '<option value="' . $category_id . '-0 " style="color:#3C8DBC;">' . $name . '</option>';
			$sub_categories = $this -> model_globals -> select_where('job_sub_categories', array('using_job_category_id' => $category_id)) -> result();
			foreach ($sub_categories as $sub_category) {
				$sub_category_id = $sub_category -> job_sub_category_id;
				$sub_name = $sub_category -> name;
				$option .= '<option value="' . $category_id . '-' . $sub_category_id . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $sub_name . '</option>';
			}
			//$option .= '</optgroup>';
		}
		return $option;
		
	}

}
